package com.kmist.xiakexing.main.base;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentActivity;

public class BaseApplication extends FragmentActivity {

    public static Handler sHandler = null;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        handleScreenStyle();
        sHandler = new Handler();
    }

    private void handleScreenStyle() {
        //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        hideNavigationBar();
    }

    public void onWindowFocousChanged(boolean hasFocus){
        super.onWindowFocusChanged(hasFocus);
        if(hasFocus){
            hideNavigationBar();
        }
    }

    private void hideNavigationBar() {
        int uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION //布局隐藏导航
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN //布局全屏
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION //隐藏导航
                | View.SYSTEM_UI_FLAG_FULLSCREEN //全屏
                | View.SYSTEM_UI_FLAG_IMMERSIVE; //沉浸式系统

        //兼容性判断
        if(android.os.Build.VERSION.SDK_INT >= 19){
            uiFlags |= 0x00001000;
        }else{
            uiFlags |= View.SYSTEM_UI_FLAG_LOW_PROFILE;
        }
        getWindow().getDecorView().setSystemUiVisibility(uiFlags);
    }

    public static Handler getHandler(){
        return sHandler;
    }
}
